package com.zcxy360.sandtable.controller;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zcxy360.sandtable.domain.DrawingSchedule;
import com.zcxy360.sandtable.domain.PlanSchedule;
import com.zcxy360.sandtable.domain.StudentUnit;
import com.zcxy360.sandtable.domain.VideoSchedule;
import com.zcxy360.sandtable.service.StudentUnitService;

/**
 * 学生小节接口
 * @author 盛亚辉
 *
 */
@RequestMapping("course/student/unit")
@RestController
public class StudentUnitController {

	@Autowired
	private StudentUnitService studentUnitService;
	
	/**
	 * 获取学生小节集合
	 * @param studentUnit 学生小节字段
	 * @param orderByClause 排序规则
	 * @param pageNum 页码
	 * @param pageSize 页数
	 * @param navigatePages 导航数
	 * @return 学生小节集合
	 */
	@RequiresRoles(value= {"teacher","student"},logical=Logical.OR)
	@GetMapping
	public Object list(StudentUnit studentUnit,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return studentUnitService.list(studentUnit,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	@RequiresRoles(value= {"teacher","student"},logical=Logical.OR)
	@GetMapping("listWithStageUnitCascade")
	public Object listWithStageUnitCascade(StudentUnit studentUnit,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return studentUnitService.listWithStageUnitCascade(studentUnit,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	@RequiresRoles(value= {"teacher","student"},logical=Logical.OR)
	@GetMapping("listWithCascade")
	public Object listWithCascade(StudentUnit studentUnit,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return studentUnitService.listWithCascade(studentUnit,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	/**
	 * 更新学生小节
	 * @param studentUnit 学生小节字段
	 * @return 布尔值
	 */
	@RequiresRoles(value= {"teacher","student"},logical=Logical.OR)
	@PutMapping
	public Object update(StudentUnit studentUnit) {
		return studentUnitService.update(studentUnit);
	}
	
	/**
	 * 学生提交小节作业
	 * @param answerJson 作答json字符串
	 * @return 布尔值
	 */
	@RequiresRoles("student")
	@PutMapping("submit")
	public Object submit(String answerJson) {
		return studentUnitService.submit(answerJson);
	}
	
	/**
	 * 作业退回
	 * @param studentUnitKey 学生小节主键
	 * @return 布尔值
	 */
	@RequiresRoles("teacher")
	@PutMapping("back")
	public Object back(@RequestParam("courseId") Integer courseId,@RequestParam("userId") Integer userId,@RequestParam("unitId") Integer unitId) {
		return studentUnitService.back(courseId,userId,unitId);
	}
	
	/**
	 * 老师打分
	 * @param markJson 打分json字符串
	 * @return 布尔值
	 */
	@RequiresRoles("teacher")
	@PutMapping("mark")
	public Object mark(@RequestParam("markJson") String markJson) {
		return studentUnitService.mark(markJson);
	}
	
	/**
	 * 学生使用教案
	 * @param planSchedule 教案进度字段
	 * @return 布尔值
	 */
	@RequiresRoles("student")
	@PutMapping("usePlan")
	public Object usePlan(PlanSchedule planSchedule) {
		return studentUnitService.usePlan(planSchedule);
	}
	
	/**
	 * 学生使用视频
	 * @param videoSchedule 视频进度字段
	 * @return
	 */
	@RequiresRoles("student")
	@PutMapping("useVideo")
	public Object useVideo(VideoSchedule videoSchedule) {
		return studentUnitService.useVideo(videoSchedule);
	}
	
	/**
	 * 学生使用图纸
	 * @param drawingSchedule 图纸进度字段
	 * @return 布尔值
	 */
	@RequiresRoles("student")
	@PutMapping("useDrawing")
	public Object useDrawing(DrawingSchedule drawingSchedule) {
		return studentUnitService.useDrawing(drawingSchedule);
	}
	
	
}
